package Q883

class Main2 {

}

class Solution {
    fun projectionArea(grid: Array<IntArray>): Int {
        var r = 0
        val arr = IntArray(grid[0].size)
        for (i in grid.indices) {
            var max = 0
            for (j in 0 until grid[i].size) {
                if (grid[i][j] != 0) {
                    r++
                    max = Math.max(max, grid[i][j])
                    arr[j] = Math.max(arr[j], grid[i][j])
                }
            }
            r += max
        }
        for (i in arr) {
            r += i
        }
        return r
    }
}